TARGET = cmz
INTERFACE = cmz.i
WRAPFILE = $(TARGET)_wrap.c
WRAPOBJ = $(TARGET)_wrap.o
MODULE = _$(TARGET).so
MODULE_DIR = module
SRCS = cmz.c rand.c
COBJS = $(SRCS:.c=.o)
SWIGOPT = -python
PYTHONBIN = $(shell echo `which python`)
PYTHONINC = $(shell echo "import sys; print sys.prefix+'/include/python'+str(sys.version_info[0])+'.'+str(sys.version_info[1])" | ${PYTHONBIN})

all: cmz

cmz: $(SRCS) main.c
	gcc -Wall -lm $(SRCS) main.c -o $(TARGET)

module_lnx: $(SRCS) $(INTERFACE)
	swig $(SWIGOPT) $(INTERFACE)
	gcc -Wall -fpic -c $(SRCS) $(WRAPFILE) -I$(PYTHONINC)
	gcc -shared -lm  $(COBJS) $(WRAPOBJ) -o $(MODULE)
	mkdir $(MODULE_DIR)
	mv $(TARGET).py $(MODULE) $(MODULE_DIR)

module_mac: $(SRCS) $(INTERFACE)
	swig $(SWIGOPT) $(INTERFACE)
	gcc -I$(PYTHONINC) -framework Python -bundle -bundle_loader $(PYTHONBIN) $(SRCS) $(WRAPFILE) -o $(MODULE)
	mkdir $(MODULE_DIR)
	mv $(TARGET).py $(MODULE) $(MODULE_DIR)

example: cmz.c rand.c example.c

	gcc -Wall -c cmz.c rand.c example.c
	gcc -lm cmz.o rand.o example.o -o example

clean: 
	rm -f $(TARGET) $(WRAPFILE) $(WRAPOBJ) *.o example 
	rm -rf module

